package resource

import (
	"errors"
	"multitude-cloud-exporter/pkg/resource/common"
	h "multitude-cloud-exporter/pkg/resource/huawei"

	"github.com/prometheus/client_golang/prometheus"
)

const (
	huawei = "huawei"
	ucloud = "ucloud"
)

var (
	errNotSupportCloud = errors.New("this cloud provider is not supported at this time")
)

//TODO 可以使用选项模式，把多云结构体抽象出公用 私用
func NewResource(name, cloudId, cloud, cloudType, regionId string, others map[string]string) (common.Resource, error) {
	br := &common.BaseResource{
		Name:      name,
		Cloud:     cloud,
		CloudID:   cloudId,
		CloudType: cloudType,
		Others:    others,
		Registry:  prometheus.NewRegistry(),
		Labels:    nil,
		Metrics:   nil,
	}
	if err := br.Registry.Register(br); err != nil {
		return nil, err
	}
	//TODO SetLabels 设计
	br.Labels = map[string]string{
		"cloud":         cloud,
		"resource_id":   cloudId,
		"resource_type": cloudType,
		"region_id":     regionId,
	}

	switch cloud {
	case huawei:
		return h.NewResource(br)
	case ucloud:
		//TODO
	}
	return nil, errNotSupportCloud
}

func BatchUpdateMetrics(key, cloud, cloudType, regionId string, others map[string]string) {
	switch cloud {
	case huawei:
		h.BatchUpdateMetrics(key, regionId, cloudType)
	case ucloud:
		//TODO
		return
	}

}
